//
// Created by 周智超 on 2020/6/21.
//

#include "array.h"
#include <iostream>
#include "gtest/gtest.h"

TEST(array, operate)
{
    int A[maxSize][maxSize];
    int B[maxSize][maxSize];
    int C[maxSize][maxSize];
    int m = 5;
    int n = 5;
    for(int i = 0; i < m; i++)
    {
        for (int j = 0; j < n; ++j) {
            if(i >= j) {
                A[i][j] = 1;
            } else
            {
                A[i][j] = 0;
            }
        }
    }
    trsmat(A, B, m, n);
    ASSERT_EQ(B[1][0], 0);
    ASSERT_EQ(A[1][0], 1);
    ASSERT_EQ(A[0][1], 0);
    ASSERT_EQ(B[0][1], 1);


    add(C, A, B, m, n);
    ASSERT_EQ(C[1][0], 1);
    ASSERT_EQ(C[0][1], 1);

    mutmat(C, A, B, m, m, m);
    printArr(A, m, n);
    std::cout << std::endl;
    printArr(B, m, n);
    std::cout << std::endl;

    printArr(C, m, n);


}

TEST(exercise, moveZero)
{
    int A[] = {0,1,0,3,12,0,8,5,0,0,7};
    moveZero(A, sizeof(A) / sizeof(A[0]));
    for(int i = 0; i < sizeof(A)/sizeof(A[0]); i++)
    {
        std::cout << A[i] << " ";
    }
    std::cout << std::endl;

}

TEST(exercise, recursiveFloatArr)
{
    float a[] = {2.1, 3.8, 15.2, 7.3 , 9.2};
    int len = sizeof(a) / sizeof(a[0]);
    float flag;
    flag = recurMax(a, len);
    ASSERT_FLOAT_EQ(flag, 15.2);
    ASSERT_FLOAT_EQ(37.6, recurSum(a, len));
    ASSERT_FLOAT_EQ(7.52, recurAverage(a, len));
}

TEST(exercise, partition)
{
    int a[] = {6,5,1,2,10,4,7};
    int len = sizeof(a) / sizeof(a[0]);
    partition(a, len);
    printArr(a, len);
}


TEST(exercise, oddFirst)
{
    int nums[] =  {1,2,3,4};
    oddFirst(nums, 4);
    for(int i = 0; i < 4; i++)
    {
        std::cout << nums[i] << " ";
    }
    std::cout << std::endl;
}

TEST(exercise, printMinMax)
{
    int a[5][maxSize] = {
            {1,2,3,4,5},
            {2,3,4,5,1},
            {3,4,5,1,2},
            {4,5,1,2,3},
            {5,1,2,3,4}
    };
    printMinAndMax(a, 5, 5);
}
TEST(exercise, addAndMul) {
    int a[][maxSize] = {
            {1, 2, 3},
            {4, 0, 6}
    };
    int a1[][maxSize] = {
            {1, 0, 0},
            {0, 0, 6}
    };
    int a2[][maxSize] = {
            {1, 0},
            {0, 0},
            {0, 6},
    };
    int b[maxSize][3];
    int c[maxSize][3];
    int d[maxSize][3];
    int e[maxSize][3];
    int f[maxSize][3];
    constructTriple(a, 2, 3,  b);
    constructTriple(a1, 2, 3, c);
    addTriple(b, c, d);
    printTriple(d);
    ASSERT_EQ(d[0][0], 5);
    constructTriple(a2, 3, 2, e);
    mulTriple(b, e, f);
    std::cout << std::endl;
    printTriple(f);




}
TEST(exercise, findInTriple)
{
    int a[][maxSize] = {
            {1,2,3},
            {4,5,6}
    };
    int b[maxSize][3];
    int c[maxSize][3];
    int flag;
    constructTriple(a, 2, 3, b);
    transposeTriple(b, c);
    ASSERT_EQ(c[1][0], 1);
    ASSERT_EQ(c[2][0], 4);
    printTriple(c);


    flag = findInTriple(b, 3);
    ASSERT_EQ(flag, 1);
    flag = findInTriple(b, 0);
    ASSERT_EQ(flag, 0);
    a[0][2] = 0;
    constructTriple(a, 2, 3, b);
    flag = findInTriple(b, 3);
    ASSERT_EQ(flag, 0);
    flag = findInTriple(b, 0);
    ASSERT_EQ(flag, 1);
}


int main(int argc,char *argv[])
{
    testing::InitGoogleTest(&argc, argv);//将命令行参数传递给gtest
    return RUN_ALL_TESTS();   //RUN_ALL_TESTS()运行所有测试案例
}
